package leetcode.method.pointer;

public class Program80RemoveRepeatElementII {
    public Program80RemoveRepeatElementII() {
    }

    public int removeDuplicates(int[] nums) {
        int k = 2;
        if (nums.length <= k) {
            return nums.length;
        }
        return removeDuplicates(nums, k);
    }

    public int removeDuplicates(int[] nums, int k) {
        int i = k - 1, j = k;
        while (j < nums.length) {
            if (nums[j] != nums[i - k + 1]) {
                nums[i + 1] = nums[j];
                i++;
            }
            j++;
        }
        return i + 1;
    }

    public static void main(String[] args) {
        Program80RemoveRepeatElementII myStack = new Program80RemoveRepeatElementII();
        int[] nums = new int[]{0,0,1,1,1,1,2,3,3};
        System.out.println(myStack.removeDuplicates(nums)); // 返回
    }
}
